<template>
  <div>
    <div>
      <el-cascader
        v-model="select"
        :options="dataOptions"
        :props="{ expandTrigger: 'hover' }"
        placeholder="请选择需要修改的数据"
        @change="handleChange"
        style="width: 50%"></el-cascader>
      <el-button type="primary" style="float: right" @click="confirmChange"
        >确认更改</el-button
      >
    </div>
    <div style="margin-top: 30px">
      <el-input
        v-model="content"
        :disabled="isDisable"
        type="textarea"
        show-word-limit
        maxlength="150"
        :autosize="{ minRows: 15, maxRows: 20 }"
        style="width: 100%"></el-input>
    </div>
  </div>
</template>
<script>
import { search3D, update3D } from '../../api/index'
export default {
  name: 'dataManage',
  data() {
    return {
      select: '',
      content: '',
      id: '',
      isDisable: true,
      dataOptions: [
        {
          value: '前台',
          label: '前台',
          children: [
            {
              value: '电脑',
              label: '电脑',
            },
            {
              value: '桌子',
              label: '桌子',
            },
          ],
        },
        {
          value: '诊疗室',
          label: '诊疗室',
          children: [
            {
              value: '电脑',
              label: '电脑',
            },
            {
              value: '工具箱',
              label: '工具箱',
            },
          ],
        },
        {
          value: '药房',
          label: '药房',
          children: [
            {
              value: '药架',
              label: '药架',
            },
            {
              value: '电脑',
              label: '电脑',
            },
          ],
        },
      ],
    }
  },
  methods: {
    handleChange() {
      let data = {}
      data.name = this.select[1]
      data.department = this.select[0]
      search3D(data).then((res) => {
        console.log(res)
        if (res.data.code == 200) {
          this.content = res.data.data.content
          this.id = res.data.data.id
          this.isDisable = false
        } else {
          this.$message.error(res.data.message)
        }
      })
    },
    confirmChange() {
      if (this.content == '') {
        this.$message.error('请输入内容！')
      } else {
        let data = {}
        data.content = this.content
        data.threeD_id = this.id
        update3D(data).then((res) => {
          console.log('ressssssssss', res)
          if (res.data.code == 200) {
            this.$message.success('修改成功！')
            this.content = ''
            this.isDisable = true
          }
        })
      }
    },
  },
}
</script>
<style scoped></style>
